# #创造序列 list(range(start,end,step)  step=1时可不加
# a=list(range(1,8,1))   #[1, 2, 3, 4, 5, 6, 7]
# print(a)
# b=[x*2 for x in range(0,100,2)]  # [0, 4, 8, 12, 16, 20]
# print(b)
#
# #用for循环创造一个列表/序列
# c=[x for x in range(1,100) if x%3==0]  #[3, 6, 9, 12, 15, 18, 21, 24, 27]
# print(c)
#
# # append 在元素后面添加一个元素
# d=[20,40]
# d.append(60)
# print(d)
#
# #+运算符在元素后面也可添加一个元素
# e=[20,30,40]
# e=e+[50]
# print(e)


#extend方法
# a=[20,40]
# print(id(a))
# b=[50,60]
# a.extend(b)
# print(a)

#insert()插入操作
# a=[10,20,30]
# a.insert(1,100)  #在元素下表前面插入
# print(a)


#删除元素操作
# a=[100,200,300,400,500]
# # del a[2] 把300删除了
# a.pop() #如果什么都不写就默认把最后一个删除了
# print(a)

#列表元素的访问
# a=[10,20,30,40,50,60]
# print(a[3])

#index()可以获取指定元素在列表首次出现的位置 index(value,[start,[end]])
# a=[10,20,30,40,50,20,30,20,30] #0 1 2 3....
# print(a.index(20))
# print(a.count(20)) #count用来数元素出现的次数
# print(len(a))#数元素长度

#切片操作
# a=[1,2,3,4,5,6,7]
# print(a[1:4])  # [2, 3, 4]
# print(a[::-1]) # [7, 6, 5, 4, 3, 2, 1] 从右往左打印
# print(a[-5:-2]) # [3, 4, 5]
# print(a[-3:])  #[5, 6, 7]倒数三个


#遍历关键字temp
# a=[1,2,3,4]
# for temp in a:
#     print(a)
#     break

#
# list1=[1,2,3,4]
# list2=[]+list1
# print(list2)
# print(id(list2))
# print(id(list1))


# 排序.sort升序 .sort(reverse=Ture)  随机数random.shuffle()
# a=[9,7,4,3,8,2]
# print(a)
# a.sort()
# print(a) # [2, 3, 4, 7, 8, 9]  升序
# b=[1,2,3,4,5,6,7]
# print(b)
# b.sort(reverse=True)
# print(b)  #[7, 6, 5, 4, 3, 2, 1]  降序
# f=[1,5,2,3,9,7,0]
# g=sorted(f)
# print(g)
# print(f)
# h=sorted(f,reverse=True)
# print(h)






#随机数random.shuffle()
# import random
# c=[1,2,3,4,5,6,7]
# random.shuffle(c)
# print(c)  #[1, 6, 4, 2, 7, 3, 5]随机排序并打印


#关键字max min sum
# a=[1,2,3,4,5,56]
# print(max(a))
# print(min(a))
#
# print(sum(a))


#列表
#
# a=[
#      ["陈冠宇", 19,20000,"上海"],
#      ["畅子丫",19,20000,"郑州"],
#      ["郭路冉",19,20000,"西安"]
#   ]
# #print(a[1][0],a[1][1],a[1][2],a[1][3])
# for m in range(3):
#     for n in range(4):
#         print(a[m][n],end="\t")
#         print()

#tuple元组;注：元组属于不可变数列,列表属于不可变数列
# a=(10,20,30)
# b=20,80,90
# c=(10,)
# print(type(a))   #均属于不可变元组tuple wa
# print(type(b))
# print(type(c))

#元组的访问与计数
# a=(10,20,30,40,9)
# print(a[2]) #30
# print(a.count(9))  #1
# print(a.index(30)) # 2
# print(a[1:4])  #(20, 30, 40)
# b=sorted(a)
# print(b) #[9, 10, 20, 30, 40] 列表对象
# a=(10,20,30)
# b=(20,30,40)
# c=(100,20,59)
# d=zip(a,b,c)
# print(d)
# e=list(d)
# print(e) #[(10, 20, 100), (20, 30, 20), (30, 40, 59)]


# a=[x*2 for x in range(5)]
# print(a)  #[0, 2, 4, 6, 8]
# b=(x*10 for x in range(5))
# c=tuple(b)  #当变量被定义为元组时不能直接打印
# print(c)   #(0, 10, 20, 30, 40)
# e=(x for x in range(3))
# print(e.__next__())
# print(e.__next__())
# print(e.__next__())

#字典
# a={'name':'guanyu','age':19, 'job':'programmer'}
# print(a)  #{'name': 'guanyu', 'age': 19, 'job': 'programmer'}
# print(a['name'])  #guanyu
# b=dict(name='gaoqi',age=18,job="programmer")  #字典
# print(b)
# k=["name","age","job"]
# v=["gaoqi",18,"programmer"]
# print(list(zip(k,v)))  #[('name', 'gaoqi'), ('age', 18), ('job', 'programmer')]
# d=dict(zip(k,v))
# print(d)
# f=dict.fromkeys(["name","age","job"])
# print(f)

#推荐使用get来获取
# a={"name":"guanyu",'age':18,"job":"student"}
# print(a["name"])
# b=a.get("age")
# c=a.get("job","一个职业")
# print(b)
# print(c)
# d=a.items()
# print(d) #dict_items([('name', 'guanyu'), ('age', 18), ('job', 'student')])
# k=a.keys() #dict_keys(['name', 'age', 'job'])
# v=a.values()#dict_values(['guanyu', 18, 'student'])
# print(k)
# print(v)
# num=len(a)
# print(num) #3
# print("name"in a) #True

#字典的添加与修改和删除
# a={"name":"guanyu","age":18,"job":"programmer"}
# a["address"]="上海建桥学院" #添加元素
# a["age"]=19 #修改元素
# print(a)  #{'name': 'guanyu', 'age': 19, 'job': 'programmer', 'address': '上海建桥学院'}

#关键字update
# a={"name":"guanyu","age":18,"job":"programmer"}
# b={"name":"guanyu","money":10000,"gender":"man"}
# a.update(b)  #使用update将旧字典中的内容进行添加，重复的不变，没有的直接新增
# print(a)

#字典元素的删除·
# a={"name":"guanyu","age":18,"job":"programmer"}
# del (a["name"])
# print(a)  #{'age': 18, 'job': 'programmer'}删除了name这个元素

#序列解包
# s={"name":"guanyu","age":18,"job":"programmer"}
# a,b,c=s #对元素名字
# d,e,r=s.values() #对值
# t,y,u=s.items()#返回的是元组
# #print(a) #name
# print(a[0],a[1])
# print(d)  #guanyu
# print(t) #('name', 'guanyu')

#字典_复杂表格数据存储_列表和字典综合嵌套
# a1={"name":"陈冠宇","age":18,"salary":30000,"city":"上海"}
# a2={"name":"李坛生","age":19,"salary":20000,"city":"北京"}
# a3={"name":"畅子丫","age":20,"salary":10000,"city":"深圳"}
# tb=(a1,a2,a3)
# # print(tb)
# # print(tb[1].get("salary"))
# # for i in range(len(tb)):
# #     print(tb[i].get("city"))
# for i in range(len(tb)):
#         print(tb[i].get("name"),tb[i].get("age"),tb[i].get("salary"),tb[i].get("city"))

#集合
# a={3,5,7}
# a.add(4) #添加
# print(a)
# a={'b','a','c','b'}
# b=set(a)  #{'a', 'b', 'c'} 覆盖了重复元素
# # print(a)
# a={10,20,30,40}
# a.remove(20) #{40, 10, 30}删除指定元素
# print(a)

#交集并集差集运算
# a={1,2,"guanyu","ziya"}
# b={"he","ziya","haha"}
# c=a|b #并集 {1, 2, 'guanyu', 'he', 'ziya', 'haha'}
# print(c)
# d=a&b
# print(d) #{'ziya'}交集
# e=a.difference(b) #差集  {1, 2, 'guanyu'}
# print(e)

